var viewport;
var tree_ss;
function logout() {
	location = "j_spring_security_logout";
}
function assistant() {
	if (getOs() == 1) {
		var e = document.getElementById('east').style.display;
		if (e == "") {
			document.getElementById('east').style.display = "none";
		} else if (e == "none") {
			document.getElementById('east').style.display = '';
		}
	} else {
		Ext.Msg.alert('警告', '您使用的是非IE内核的浏览器，此功能无法使用！');
	}
}
function getOs() {
	if (navigator.userAgent.indexOf("MSIE") > 0)
		return 1;
	if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0)
		return 2;
	if (isSafari = navigator.userAgent.indexOf("Safari") > 0)
		return 3;
	if (isCamino = navigator.userAgent.indexOf("Camino") > 0)
		return 4;
	if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0)
		return 5;
	return 0;
}
Ext.ux.IFrameComponent = Ext.extend(Ext.BoxComponent, {
			onRender : function(ct, position) {
				this.el = ct.createChild({
							tag : 'iframe',
							id : 'iframe_' + this.id,
							frameBorder : 0,
							src : this.url
						});
			}
		});

function getMenu(tree) {

	Ext.Ajax.request({
				url : 'bindAsTree!bindAsTree.action', // MenuAction 拼装tree 返回
				method : "post",
				success : function(response, options) {
					var responseTextVale = Ext.util.JSON
							.decode(response.responseText);
					tree.getRootNode().appendChild(Ext.util.JSON
							.decode(responseTextVale));
				}
			});
}

Ext.onReady(function() {
	Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8';
	Ext.QuickTips.init();

	var root = new Ext.tree.AsyncTreeNode({
				expanded : true
			});

	var tree = new Ext.tree.TreePanel({
				loader : new Ext.tree.TreeLoader(),
				id : 'menuTree',
				title : '菜单栏',
				region : 'west',
				rootVisible : false,
				split : true,
				border : true,
				collapsible : true,
				layout : 'accordion',
				width : 151,
				minSize : 100,
				maxSize : 200,
				// margins: '0 0 0 60',
				animate : true,
				autoScroll : true,
				enableDD : false,
				containerScroll : true

			});

	getMenu(tree);

	tree.setRootNode(root);

	tree.on("click", function(node) {
		if (node.attributes.action == undefined) {
			// 不做任何处理
		} else if (node.attributes.action == ''
				|| node.attributes.action == 'null') {
			// url 没有定义 提示
			alert(node.text + ': 未计划');
		} else {
			// top.location = "intoLogin.action";
			document.getElementById("iframe_test").contentWindow.location = node.attributes.action;
		}
	});

	var viewport = new Ext.Viewport({
				renderTo : document.body,
				layout : 'border',
				id : 'panel',
				// width: window.screen.availWidth,
				height : 600,
				border : false,
				items : [new Ext.BoxComponent({
									region : 'north',
									el : 'north'
								}), new Ext.BoxComponent({
									region : 'south',
									el : 'south'
								}), tree, {
							region : 'center',
							id : 'centerPanel',
							deferredRender : false,
							split : true,
							border : false,
							layout : 'fit',
							items : [new Ext.ux.IFrameComponent({
										id : 'test',
										url : 'about:blank'
									})]
						}]
			});
});
